#!/usr/bin/env bash
#########################################################################
# File Name   : nova.sh.j2
# Author      : seadog
# mail        : seadog0514@163.com
# Version     : 0.1
# Created Time: Mon 2024-09-30 13:17:38(+0800)
#########################################################################

#
#
# Usage:

{
  set -euo pipefail
}

# !!! error:
if [[ $(hostname -f) == "{{ openstack_master_hostname }}" ]]; then
  source /root/keystonerc
  # openstack error Error: Host 'u22-150' is not mapped to any cell
  nova-manage cell_v2 discover_hosts --verbose
fi

# !!! error:
# Refusing to bind port 40a7d464-bdb6-40db-a85f-23e10528bdd5 due to no OVN chassis for host: openstack81
# neutron using hostname 'openstack81', by default ovs-vsctl use hostname 'openstack81.lab.seadog.com'
ovs-vsctl set open . external-ids:hostname="$(hostname)"
ovs-vsctl list open_vswitc

# !!! nova use qemu
if [[ $(hostname -f) != "{{ openstack_master_hostname }}" ]]; then
  use_kvm="{{ use_kvm }}"
  if [[ ${use_kvm} == "False" ]]; then
    sed -i 's/virt_type=kvm/virt_type=qemu/' /etc/nova/nova-compute.conf
    systemctl restart nova-compute.service
  fi
fi
